<?php
class SNSGroup extends Eloquent {
	protected $table = 'sns_group';

	public function members()
	{
		return $this->hasMany('SNSGroupMember', 'group_id');
	}
	
	public function admins()
	{
		$group_admins = SNSGroupMember::where('group_id', $this->id)->where('is_creator',1)->get(); 
		$ret = [];
		foreach (($group_admins) as $gadmin ){
			$ret[] = User::where('id',$gadmin->user_id)->first();
		}
		return $ret;
	}
	
	public static function getSNSGroupId($easemob_id){
		$SNSGroup = SNSGroup::where('easemob_id', $easemob_id)->first();
		return $SNSGroup?$SNSGroup->id:'0';

	}
}